package com.gxa.controller.investment;

import com.github.pagehelper.PageInfo;
import com.gxa.common.utils.Result;
import com.gxa.entity.investment.BusinessTypeChild;
import com.gxa.entity.investment.Company;
import com.gxa.entity.investment.Project;
import com.gxa.entity.investment.ProjectCenter;
import com.gxa.service.investment.*;
import com.gxa.vo.ProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "项目管理/项目详情")
@RestController
@RequestMapping("/projectdetail")
public class ProjectDetailController {
    @Autowired
    private ProjectCenterService projectCenterService;
    @Autowired
    private ProjectService projectService;
    @Autowired
    private ProjectDetailsService projectDetailsService;
    @Autowired
    private RiskTraceService riskTraceService;
    @Autowired
    private CompanyService companyService;

    @Autowired
    private BusinessTypeChildService businessTypeChildService;

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("列表接口")
    @PostMapping("/list/{pageNum}/{pageSize}")
    public Result<PageInfo> seletAll(@PathVariable("pageNum") Integer pageNum,
                                     @PathVariable("pageSize") Integer pageSize){
        PageInfo<ProjectCenter> pageInfo = this.projectCenterService.queryAll(pageNum, pageSize);
        return Result.success(pageInfo);
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("条件查询列表接口")
    @PostMapping("/listVo")
    public Result<PageInfo> seletAll(@RequestBody ProjectVo projectVo){
        PageInfo<ProjectCenter> pageInfo = this.projectCenterService.queryByVo(projectVo);
        return Result.success(pageInfo);
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("根据id查询列表接口")
    @PostMapping("/list")
    public Result<Map> queryById(Integer id, Integer status){
        Map map = new HashMap();
        Project project = this.projectService.queryById(id);
        List list = this.projectDetailsService.queryTime(id, status);
        map.put("project",project);
        map.put("list",list);
        return Result.success(map);
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("风险预警列表接口")
    @PostMapping("/riskTrace")
    public Result<PageInfo> queryByriskTraceId(Integer id,Integer pageNum, Integer pageSize) {
        PageInfo pageInfo = this.riskTraceService.queryById(id, pageNum, pageSize);
        return Result.success(pageInfo);

    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("企业接口")
    @PostMapping("/company")
    public Result<Company> queryByComPanyId(Integer id) {
        Company company= this.companyService.queryById(id);
        return Result.success(company);

    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("行业小类")
    @PostMapping("/businessChildType/{businessTypeChildCoding}")
    public Result<BusinessTypeChild> queryByCoding(@PathVariable("businessTypeChildCoding") Integer businessTypeChildCoding) {
        BusinessTypeChild businessTypeChild = this.businessTypeChildService.queryById(businessTypeChildCoding);
        return Result.success(businessTypeChild);
    }
}
